<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Widget controller for SAEF widget
 * 
 * @package PyroCMS
 * @subpackage Blog SAEF Module
 * @category Modules
 * @category Widgets 
 * @author Rick Holmes
 * @version 1.0 
 */    
class Widget_Saef extends Widgets { 
	
	public $title = 'Stand Alone Entry Form';
	
	public $description = 'A form that allows logged-in users to post to the blog from a page.';

	public $author = 'Rick Holmes';
	
	public $website = '';
	
	public $version = '1.0';
	
	private $categories;
	
	public function __construct()
	{
		$this->load->model('saef/saef_m');
		$this->lang->load('saef/saef');
		
		$this->categories = $this->saef_m->get_allowed_categories();
		$this->requires_moderation = $this->saef_m->requires_moderation();
	}
	
	/**
	 * Runs code and logic required to display the widget.
	 *
	 * @param void
	 * @return	function|bool FALSE
	 */
	public function run()
	{
		if ($this->saef_m->is_enabled() && $this->categories)
		{
			$allowed_users = $this->saef_m->get_allowed_group_ids();
			
			if ($this->ion_auth->logged_in() && in_array($this->current_user->group_id, $allowed_users))
			{
				return $this->_form();
			}
		}
			
		return FALSE;
	}
	
	/**
	 * form() is used to prepare/pass data to the widget admin form
	 * 
	 * @param void
	 * @return array	 	 
	 */
	private function _form()
	{	
		return array('categories' => $this->categories, 'requires_moderation' => $this->requires_moderation);
	 }
}
/* End of file saef.php */
/* location /addons/shared_addons/]modules/saef/widgets/saef/saef.php */